// Written by Marco
Class KFBotsMut extends Mutator
	Config(UnitedMut);

var() config array<string> BotPerks;
var() config int NumBots;
var() config int MaxVeteranLevel,MinVeteranLevel;
var KFGameType KF;
var float NextTraderMsg,NextYellTime;
var array< class<KFVeterancyTypes> > LoadedSkills;
var bool bDoPendingWelcome;

static function FillPlayInfo(PlayInfo PlayInfo)
{
	Super.FillPlayInfo(PlayInfo);
	PlayInfo.AddSetting(default.RulesGroup, "NumBots", "Number Bots", 0, 0, "Text",   "3;0:64");
	PlayInfo.AddSetting(default.RulesGroup, "MaxVeteranLevel", "Max Bot Vet Level", 0, 0, "Text",   "3;0:10");
	PlayInfo.AddSetting(default.RulesGroup, "MinVeteranLevel", "Min Bot Vet Level", 0, 0, "Text",   "3;0:10");
}

static event string GetDescriptionText(string PropName)
{
	switch( PropName )
	{
	case "NumBots":
		return "Number of bots should appear in game.";
	case "MaxVeteranLevel":
		return "Maximum veterancy level for bots.";
	case "MinVeteranLevel":
		return "Minimum veterancy level for bots.";
	default:
		return Super.GetDescriptionText(PropName);
	}
}

function PreBeginPlay()
{
	local int i;
	local class<KFVeterancyTypes> V;

	KF = KFGameType(Level.Game);
	if( KF==None )
	{
		Error("This is not a KF based game mode.");
		return;
	}
	KF.bNoBots = true;
	KF.bBotsAdded = true;
	KF.InitialBots = NumBots;

	for( i=0; i<BotPerks.Length; ++i )
	{
		V = Class<KFVeterancyTypes>(DynamicLoadObject(BotPerks[i],Class'Class'));
		if( V!=None )
			LoadedSkills[LoadedSkills.Length] = V;
	}
	MinVeteranLevel = Min(MinVeteranLevel,MaxVeteranLevel);
}
function MatchStarting()
{
	local byte c;

	Spawn(Class'BotBroadcastHandle');
	if( Level.NetMode==NM_StandAlone )
	{
		KF.RemainingBots = 0;
		while( ++c<=NumBots )
			AddBot();
	}
	else
	{
		KF.MinPlayers = NumBots;
		if( KF.NeedPlayers() )
			AddBot();
		SetTimer(1,true);
	}
}
function Timer()
{
	if( bDoPendingWelcome )
	{
		KF.bWelcomePending = true;
		bDoPendingWelcome = false;
	}
	if( KF.bGameEnded )
		SetTimer(0,false);
	else if( KF.NeedPlayers() )
		AddBot();
}
final function AddBot()
{
	local KFInvBots NewBot;
	local RosterEntry Chosen;
	local UnrealTeamInfo BotTeam;

	BotTeam = KF.GetBotTeam();
	Chosen = BotTeam.ChooseBotClass("");

	if( Chosen.PawnClass == None )
		Chosen.Init(); //amb
	NewBot = Spawn(class'KFInvBots');

	if ( NewBot==None )
		return;

	KF.InitializeBot(NewBot,BotTeam,Chosen);

	// Decide if bot should be a veteran.
	if ( LoadedSkills.Length > 0 && KFPlayerReplicationInfo(NewBot.PlayerReplicationInfo) != None )
	{
		KFPlayerReplicationInfo(NewBot.PlayerReplicationInfo).ClientVeteranSkill = LoadedSkills[Rand(LoadedSkills.Length)];
		if( MinVeteranLevel==MaxVeteranLevel )
			KFPlayerReplicationInfo(NewBot.PlayerReplicationInfo).ClientVeteranSkillLevel = MaxVeteranLevel;
		else KFPlayerReplicationInfo(NewBot.PlayerReplicationInfo).ClientVeteranSkillLevel = MinVeteranLevel+Rand(MaxVeteranLevel+1-MinVeteranLevel);
	}

	NewBot.Mute = Self;
	NewBot.SetFaveGun();
	NewBot.PlayerReplicationInfo.Score = KF.StartingCash;
	NewBot.PlayerReplicationInfo.PlayerID = KF.CurrentID++;
	NewBot.Skill = 9;
	NewBot.Accuracy = 1;
	KF.NumBots++;
	if ( Level.NetMode == NM_Standalone )
		KF.RestartPlayer(NewBot);
	else NewBot.GotoState('Dead','MPStart');
	bDoPendingWelcome = true;
}

defaultproperties
{
     BotPerks(0)="KFMod.KFVetFieldMedic"
     BotPerks(1)="KFMod.KFVetSupportSpec"
     BotPerks(2)="KFMod.KFVetSharpshooter"
     BotPerks(3)="KFMod.KFVetCommando"
     BotPerks(4)="KFMod.KFVetBerserker"
     BotPerks(5)="KFMod.KFVetFirebug"
     BotPerks(6)="KFMod.KFVetDemolitions"
     NumBots=4
     MaxVeteranLevel=6
     GroupName="KF-Bots"
     FriendlyName="Bots Mutator"
     Description="Add KF bots to the game."
}
